package architect.springcloud.eureka.client;

import architect.springcloud.feign.service.MessageService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客户端Controller
 *
 * @author guanxin
 * @date 2018/4/19 9:40
 */

@RestController
@Slf4j
public class ClientController {

    @Autowired
    private MessageService messageService;

    @HystrixCommand(fallbackMethod = "getMessageFail")
    @RequestMapping(value = "/getMessage")
    @ResponseBody
    public String getMessage(@RequestParam String message) {
        log.info("Client send message to provider ==============>>>>>>>>>>>>>>>>>");
        return messageService.sendMessage(message);
    }

    public String getMessageFail(String message) {
        return "Client call sendMessage fail, message = " + message;
    }
}
